CommonFileListRequertFile('ProtocolApi');
var ws = new WebSocket('ws://47.105.43.170:8283');
var times=''; //定时器
ws.onopen=function (){
    var token   = localStorage.getItem('PhpGameSocketToken');
    if(token!==false && token!=='' && token!==null){
        if(Date.parse(new Date())/1000-localStorage.getItem('PhpGameSocketTokenTime')>=60*60*2){
            localStorage.setItem('PhpGameSocketToken','');
            localStorage.setItem('PhpGameSocketTokenTime','');
            window.location.href='login.html';
        }
        var serverMsg = {head: ProtocolApi.Protocol['WEB_USER_LOGIN'], msg: {token:token}};
        msg=JSON.stringify(serverMsg);
        ws.send(msg);
    }

    times=window.setInterval(function (){
        var serverMsg = {"head": 0X100001, "msg": ''};
        var msg=JSON.stringify(serverMsg);
        ws.send(msg);
    },5000);
};

ws.onclose=function (){
    clearInterval(times);
    layer.msg('服务器已断开请刷新页面,并尝试断线重连');
};

